package org.example;

import javassist.*;

import java.io.IOException;

public class App {
    public static void main( String[] args ) throws IOException, CannotCompileException, NotFoundException, IllegalAccessException, InstantiationException {
        ClassPool pool = ClassPool.getDefault();
//        pool.insertClassPath(new ClassClassPath(Hello.class));
//        pool.insertClassPath("F:\\javacode\\javassistDemo\\javassistDemo\\src\\main\\java\\org\\example");
        CtClass hello = pool.get("org.example.Hello");
        CtMethod say = hello.getDeclaredMethod("say");
        say.insertBefore("{ System.out.println(\"say 方法之前：\"); }");
        Class<?> aClass = hello.toClass();
        Hello h = (Hello)aClass.newInstance();
        h.say();
    }
}
